﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.SqlDataSourceEmpresa.InsertParameters["cuit"].DefaultValue = this.TextBoxCUIT.Text;
        this.SqlDataSourceEmpresa.InsertParameters["razonSocial"].DefaultValue = this.TextBox2.Text;
        this.SqlDataSourceEmpresa.InsertParameters["nombreComercial"].DefaultValue = this.TextBox1.Text;
        this.SqlDataSourceEmpresa.InsertParameters["mail"].DefaultValue = this.TextBox3.Text;
        this.SqlDataSourceEmpresa.InsertParameters["numTelefono"].DefaultValue = this.TextBox4.Text;
        this.SqlDataSourceEmpresa.InsertParameters["web"].DefaultValue = this.TextBox10.Text;
        this.SqlDataSourceEmpresa.InsertParameters["calle"].DefaultValue = this.TextBox5.Text;
        this.SqlDataSourceEmpresa.InsertParameters["numCalle"].DefaultValue = this.TextBox6.Text;
        this.SqlDataSourceEmpresa.InsertParameters["piso"].DefaultValue = this.TextBox7.Text;
        this.SqlDataSourceEmpresa.InsertParameters["departamento"].DefaultValue = this.TextBox8.Text;
        this.SqlDataSourceEmpresa.InsertParameters["codigoPostal"].DefaultValue = this.TextBox9.Text;
        this.SqlDataSourceEmpresa.InsertParameters["idCondIVA"].DefaultValue = this.DropIVA.SelectedValue;
        this.SqlDataSourceEmpresa.InsertParameters["idTipoTelefono"].DefaultValue = this.DropTel.SelectedValue;
        
        /*this.SqlDataSourceEmpresa.InsertParameters["codLocalidad"].DefaultValue = this.DropLocalidad.SelectedValue;
        this.SqlDataSourceEmpresa.InsertParameters["codBarrio"].DefaultValue = this.DropBarrio.SelectedValue;
        this.SqlDataSourceEmpresa.InsertParameters["codProvincia"].DefaultValue = this.DropProvincia.SelectedValue;
        this.SqlDataSourceEmpresa.InsertParameters["codPais"].DefaultValue = this.DropPais.SelectedValue;*/

        this.SqlDataSourceEmpresa.Insert();

        Label3.Text= "Los Datos Se Registraron Correctamente";

        TextBox1.Text = "";
        TextBox10.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
        TextBox9.Text = "";
        TextBoxCUIT.Text = "";



    }
    protected void Button5_Click(object sender, EventArgs e)
    {

        this.Response.Redirect("DatosNuevaEmpresa.aspx?cuit=" + TextBoxCUIT.Text + "&mail=" + TextBox3.Text + "&razonSocial="+TextBox2.Text+"&nombreComercial="+TextBox1.Text);
              
      
    }








    protected void Button2_Click(object sender, EventArgs e)
    {

        this.SqlDataSourceEmpresa.SelectParameters["cuit"].DefaultValue = this.TextBoxCUIT.Text;
        this.SqlDataSourceEmpresa.DataSourceMode = SqlDataSourceMode.DataReader;
        SqlDataReader datos;
        datos = (SqlDataReader)this.SqlDataSourceEmpresa.Select(DataSourceSelectArguments.Empty);

        if (datos.Read())
        {
            this.TextBox2.Text = datos["razonSocial"].ToString();
            this.TextBox1.Text = datos["nombreComercial"].ToString();
            this.TextBox3.Text = datos["mail"].ToString();
            this.TextBox4.Text = datos["numTelefono"].ToString();
            this.TextBox10.Text = datos["web"].ToString();
            this.TextBox5.Text = datos["calle"].ToString();
            this.TextBox6.Text = datos["numCalle"].ToString();
            this.TextBox7.Text = datos["piso"].ToString();
            this.TextBox8.Text = datos["departamento"].ToString();
            this.TextBox9.Text = datos["codigoPostal"].ToString();
            this.DropIVA.SelectedValue = datos["idCondIVA"].ToString();
            this.DropTel.SelectedValue = datos["idTipoTelefono"].ToString();
                       

        }
        else
            TextBox1.Text = "No se encontro coincidencia";
        



    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        this.SqlDataSourceEmpresa.UpdateParameters["cuit"].DefaultValue = this.TextBoxCUIT.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["razonSocial"].DefaultValue = this.TextBox2.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["nombreComercial"].DefaultValue = this.TextBox1.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["mail"].DefaultValue = this.TextBox3.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["numTelefono"].DefaultValue = this.TextBox4.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["web"].DefaultValue = this.TextBox10.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["calle"].DefaultValue = this.TextBox5.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["numCalle"].DefaultValue = this.TextBox6.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["piso"].DefaultValue = this.TextBox7.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["departamento"].DefaultValue = this.TextBox8.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["codigoPostal"].DefaultValue = this.TextBox9.Text;
        this.SqlDataSourceEmpresa.UpdateParameters["idCondIVA"].DefaultValue = this.DropIVA.SelectedValue;
        this.SqlDataSourceEmpresa.UpdateParameters["idTipoTelefono"].DefaultValue = this.DropTel.SelectedValue;

        int cant;

        cant = this.SqlDataSourceEmpresa.Update();

        if (cant == 1)
        {
            Label3.Text = "Los Datos Se Modificaron Correctamente";

            TextBox1.Text = "";
            TextBox10.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
            TextBox5.Text = "";
            TextBox6.Text = "";
            TextBox7.Text = "";
            TextBox8.Text = "";
            TextBox9.Text = "";
            TextBoxCUIT.Text = "";
        
        
        }

        else
            Label3.Text = "Los Datos No Se Pudieron Modificar";




    }
}